package com.itheima.web;

import com.itheima.pojo.Brand;
import com.itheima.service.BrandService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/selectIdServlet")
public class SelectIdServlet extends HttpServlet {

    private BrandService selectId= new BrandService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
            ServletException, IOException {

        //接收被修改那条数据的id
        String id = request.getParameter("id");

        //调用BrandService完成查询
        Brand brand = selectId.selectId(Integer.parseInt(id));

        System.out.println(brand);

        //2. 存入request域中
        request.setAttribute("brand",brand);
        //3. 转发到brand.jsp
        request.getRequestDispatcher("/update.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
            ServletException, IOException {
        this.doGet(request, response);
    }
}
